package com.fr.base.core.serializable;

import java.awt.Shape;
import java.awt.geom.Arc2D;
import java.awt.geom.Arc2D.Double;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Ellipse2D.Double;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.Line2D.Double;
import java.awt.geom.PathIterator;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class ShapeSerializable
  implements Serializable
{
  private transient Shape shape;

  public ShapeSerializable(Shape paramShape)
  {
    this.shape = paramShape;
  }

  public Shape getShape()
  {
    return this.shape;
  }

  public void setShape(Shape paramShape)
  {
    this.shape = paramShape;
  }

  private void writeObject(ObjectOutputStream paramObjectOutputStream)
    throws IOException
  {
    paramObjectOutputStream.defaultWriteObject();
    Shape localShape = getShape();
    if (localShape == null)
    {
      paramObjectOutputStream.writeBoolean(true);
    }
    else
    {
      Object localObject;
      paramObjectOutputStream.writeBoolean(false);
      if (localShape instanceof Line2D)
      {
        localObject = (Line2D)localShape;
        paramObjectOutputStream.writeObject(Line2D.class);
        paramObjectOutputStream.writeDouble(((Line2D)localObject).getX1());
        paramObjectOutputStream.writeDouble(((Line2D)localObject).getY1());
        paramObjectOutputStream.writeDouble(((Line2D)localObject).getX2());
        paramObjectOutputStream.writeDouble(((Line2D)localObject).getY2());
      }
      else if (localShape instanceof Rectangle2D)
      {
        localObject = (Rectangle2D)localShape;
        paramObjectOutputStream.writeObject(Rectangle2D.class);
        paramObjectOutputStream.writeDouble(((Rectangle2D)localObject).getX());
        paramObjectOutputStream.writeDouble(((Rectangle2D)localObject).getY());
        paramObjectOutputStream.writeDouble(((Rectangle2D)localObject).getWidth());
        paramObjectOutputStream.writeDouble(((Rectangle2D)localObject).getHeight());
      }
      else if (localShape instanceof Ellipse2D)
      {
        localObject = (Ellipse2D)localShape;
        paramObjectOutputStream.writeObject(Ellipse2D.class);
        paramObjectOutputStream.writeDouble(((Ellipse2D)localObject).getX());
        paramObjectOutputStream.writeDouble(((Ellipse2D)localObject).getY());
        paramObjectOutputStream.writeDouble(((Ellipse2D)localObject).getWidth());
        paramObjectOutputStream.writeDouble(((Ellipse2D)localObject).getHeight());
      }
      else if (localShape instanceof Arc2D)
      {
        localObject = (Arc2D)localShape;
        paramObjectOutputStream.writeObject(Arc2D.class);
        paramObjectOutputStream.writeDouble(((Arc2D)localObject).getX());
        paramObjectOutputStream.writeDouble(((Arc2D)localObject).getY());
        paramObjectOutputStream.writeDouble(((Arc2D)localObject).getWidth());
        paramObjectOutputStream.writeDouble(((Arc2D)localObject).getHeight());
        paramObjectOutputStream.writeDouble(((Arc2D)localObject).getAngleStart());
        paramObjectOutputStream.writeDouble(((Arc2D)localObject).getAngleExtent());
        paramObjectOutputStream.writeInt(((Arc2D)localObject).getArcType());
      }
      else
      {
        if (localShape instanceof GeneralPath)
        {
          paramObjectOutputStream.writeObject(GeneralPath.class);
          localObject = localShape.getPathIterator(null);
          float[] arrayOfFloat = new float[6];
          paramObjectOutputStream.writeBoolean(((PathIterator)localObject).isDone());
          while (true)
          {
            if (((PathIterator)localObject).isDone())
              return;
            int i = ((PathIterator)localObject).currentSegment(arrayOfFloat);
            paramObjectOutputStream.writeInt(i);
            for (int j = 0; j < 6; ++j)
              paramObjectOutputStream.writeFloat(arrayOfFloat[j]);
            paramObjectOutputStream.writeInt(((PathIterator)localObject).getWindingRule());
            ((PathIterator)localObject).next();
            paramObjectOutputStream.writeBoolean(((PathIterator)localObject).isDone());
          }
        }
        paramObjectOutputStream.writeObject(localShape.getClass());
        paramObjectOutputStream.writeObject(localShape);
      }
    }
  }

  private void readObject(ObjectInputStream paramObjectInputStream)
    throws IOException, ClassNotFoundException
  {
    paramObjectInputStream.defaultReadObject();
    Object localObject = null;
    boolean bool1 = paramObjectInputStream.readBoolean();
    if (!(bool1))
    {
      double d1;
      double d2;
      double d3;
      double d4;
      Class localClass = (Class)paramObjectInputStream.readObject();
      if (localClass.equals(Line2D.class))
      {
        d1 = paramObjectInputStream.readDouble();
        d2 = paramObjectInputStream.readDouble();
        d3 = paramObjectInputStream.readDouble();
        d4 = paramObjectInputStream.readDouble();
        localObject = new Line2D.Double(d1, d2, d3, d4);
      }
      else if (localClass.equals(Rectangle2D.class))
      {
        d1 = paramObjectInputStream.readDouble();
        d2 = paramObjectInputStream.readDouble();
        d3 = paramObjectInputStream.readDouble();
        d4 = paramObjectInputStream.readDouble();
        localObject = new Rectangle2D.Double(d1, d2, d3, d4);
      }
      else if (localClass.equals(Ellipse2D.class))
      {
        d1 = paramObjectInputStream.readDouble();
        d2 = paramObjectInputStream.readDouble();
        d3 = paramObjectInputStream.readDouble();
        d4 = paramObjectInputStream.readDouble();
        localObject = new Ellipse2D.Double(d1, d2, d3, d4);
      }
      else if (localClass.equals(Arc2D.class))
      {
        d1 = paramObjectInputStream.readDouble();
        d2 = paramObjectInputStream.readDouble();
        d3 = paramObjectInputStream.readDouble();
        d4 = paramObjectInputStream.readDouble();
        double d5 = paramObjectInputStream.readDouble();
        double d6 = paramObjectInputStream.readDouble();
        int k = paramObjectInputStream.readInt();
        localObject = new Arc2D.Double(d1, d2, d3, d4, d5, d6, k);
      }
      else if (localClass.equals(GeneralPath.class))
      {
        GeneralPath localGeneralPath = new GeneralPath();
        float[] arrayOfFloat = new float[6];
        for (boolean bool2 = paramObjectInputStream.readBoolean(); !(bool2); bool2 = paramObjectInputStream.readBoolean())
        {
          int i = paramObjectInputStream.readInt();
          for (int j = 0; j < 6; ++j)
            arrayOfFloat[j] = paramObjectInputStream.readFloat();
          switch (i)
          {
          case 0:
            localGeneralPath.moveTo(arrayOfFloat[0], arrayOfFloat[1]);
            break;
          case 1:
            localGeneralPath.lineTo(arrayOfFloat[0], arrayOfFloat[1]);
            break;
          case 3:
            localGeneralPath.curveTo(arrayOfFloat[0], arrayOfFloat[1], arrayOfFloat[2], arrayOfFloat[3], arrayOfFloat[4], arrayOfFloat[5]);
            break;
          case 2:
            localGeneralPath.quadTo(arrayOfFloat[0], arrayOfFloat[1], arrayOfFloat[2], arrayOfFloat[3]);
            break;
          case 4:
            break;
          default:
            throw new RuntimeException("No GeneralPath");
          }
          localGeneralPath.setWindingRule(paramObjectInputStream.readInt());
        }
        localObject = localGeneralPath;
      }
      else
      {
        localObject = (Shape)paramObjectInputStream.readObject();
      }
    }
    setShape((Shape)localObject);
  }
}